package com.itheima.controller;

import com.itheima.domain.User;
import com.itheima.service.UserSerService;
import com.itheima.servlet.UserServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {

    @Autowired
    private UserSerService userServlet;

    @RequestMapping("/user-save")
    public String save(){
        userServlet.save();
        return "save.jsp";
    }

    @RequestMapping("/user-save2")
    public ModelAndView save2(){
        ModelAndView modAndView = new ModelAndView();
        modAndView.addObject("username","itheima");
        modAndView.setViewName("save.jsp");
        return modAndView;
    }

    @RequestMapping("/user-save3")
    @ResponseBody
    public User save3(){
        User user = new  User();
        user.setAge(1);
        user.setName("Username");
        return user;
    }

}
